﻿using System;
using System.Buffers;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using eLoop;
using eNets.IO;

namespace eNets.CBK.Sockets;

abstract class ASocketSndOper : ASocketOper
{
    public ASocketSndOper(Socket socket, SocketCompletedDelegate sndCompleted, ITaskScheduler scheduler)
        : base(socket, scheduler, sndCompleted)
    {
       this.segmentList = new SegmentList();
    }

    private SegmentList segmentList;
    

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void SendAsync(ReadOnlySequence<byte> buffers)
    {
        this.segmentList.Clear();
        foreach (var buf in buffers)
            this.segmentList.Add(buf.GetArray());
        this.SendAsync(this.segmentList);
    }
    
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void SendAsync(IList<ArraySegment<byte>> segments)
    {
        base.SetArgsBuffer(segments);
        base.SocketOperationCombineAsync();
    }
}